# Copyright 2020 Makani Technologies LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Automatically generated controllers.

This file was generated by: analysis/control/crosswind.py.
"""

from makani.control import control_types as m


def GetControllers(wing_serial):
  """Returns gain matrices for crosswind control for any kite serial number."""
  if wing_serial == m.kWingSerialOktoberKite01:
    airspeed_table = (
        [30.0, 60.0, 90.0]
    )
    flap_offsets = (
        [-0.045, -0.045, 0.0, 0.0, -0.155, -0.155, 0.166, -0.017]
    )
    longitudinal_gains_min_airspeed = (
        [[-0.007, 0.02, -0.719, -0.223, 0.315],
         [5.714, -14.91, 508.697, 161.809, -223.462]]
    )
    longitudinal_gains_nominal_airspeed = (
        [[0.005, 0.009, -0.611, -0.133, 0.316],
         [-0.912, -1.746, 108.01, 24.43, -56.199]]
    )
    longitudinal_gains_max_airspeed = (
        [[0.004, 0.005, -0.545, -0.116, 0.316],
         [-0.289, -0.46, 42.458, 9.505, -24.87]]
    )
    lateral_gains_min_airspeed = (
        [[2.04, -1.084, -0.363, 0.318, -0.872, 0.243],
         [0.058, 1.315, -0.003, -0.685, -0.382, -0.374],
         [-7653.188, -36406.467, 815.752, 23742.727, 15370.812, 11304.581]]
    )
    lateral_gains_nominal_airspeed = (
        [[1.556, -0.862, -0.192, 0.172, -0.872, 0.244],
         [0.206, 1.339, -0.014, -0.433, -0.479, -0.431],
         [-3026.36, -9415.53, 210.962, 3899.085, 4811.219, 3353.69]]
    )
    lateral_gains_max_airspeed = (
        [[1.45, -0.793, -0.165, 0.128, -0.88, 0.237],
         [0.134, 1.292, -0.011, -0.32, -0.472, -0.439],
         [-1045.771, -3930.004, 71.645, 1312.096, 2101.664, 1498.471]]
    )
    B_flaps_to_pqr_min_airspeed = (  # pylint: disable=invalid-name
        [[-6.601, -0.013, 0.145], [0.048, -7.687, 0.003], [0.942, 0.02, -1.406]]
    )

  else:
    assert False, 'wing_serial %d was not recognized' % wing_serial

  return {
      'airspeed_table': (
          airspeed_table),
      'flap_offsets': (
          flap_offsets),
      'longitudinal_gains_min_airspeed': (
          longitudinal_gains_min_airspeed),
      'longitudinal_gains_nominal_airspeed': (
          longitudinal_gains_nominal_airspeed),
      'longitudinal_gains_max_airspeed': (
          longitudinal_gains_max_airspeed),
      'lateral_gains_min_airspeed': (
          lateral_gains_min_airspeed),
      'lateral_gains_nominal_airspeed': (
          lateral_gains_nominal_airspeed),
      'lateral_gains_max_airspeed': (
          lateral_gains_max_airspeed),
      'B_flaps_to_pqr_min_airspeed': (
          B_flaps_to_pqr_min_airspeed),
  }
